package com.sm.scorpio.ui.base;

import android.content.Intent;

import com.sm.scorpio.http.BasicsActivityInter;
import com.scorpio.baselibrary.ui.BasicTitleActivity;
import com.scorpio.baselibrary.utils.ActivityManagement;
import com.scorpio.baselibrary.utils.AppDataUtil;
import com.sm.scorpio.ui.activity.login.LoginActivity;
import com.sm.scorpio.ui.dialog.DialogManager;
import com.sm.scorpio.ui.bean.model.UserBean;

/**
 * created by zhud on 2018/10/26
 */
public abstract class BaseActivity extends BasicTitleActivity implements BasicsActivityInter {

    @Override
    public void showLoadingView() {
        DialogManager.getInstance().showLoading(this);
    }

    @Override
    public void closeLoadingView() {
        DialogManager.getInstance().dismissLoadingDialog();
    }

    @Override
    public void showMessage(String msg) {

    }

    @Override
    public void closeMessage() {

    }

    @Override
    public void outAccToLoginActivity(String url) {
        AppDataUtil.getInstance().clearCache(UserBean.class);
        skipActivityFinish(LoginActivity.class);
    }

    @Override
    public void onNetworkLoadingSuccess(String url, Object data) {
        closeLoadingView();
    }

    @Override
    public void onNetworkLoadingFail(int code, String url) {
        closeLoadingView();
    }

    @Override
    public void onShowToast(String msg) {
        toast(msg);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DialogManager.getInstance().dismissAllDialog();
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        if (ActivityManagement.getInstance().getActivityCount() != 0)
            overridePendingTransition(com.scorpio.baselibrary.R.anim.slide_in_right, com.scorpio.baselibrary.R.anim.slide_out_left);
    }

    @Override
    public void finish() {
        super.finish();
        if (ActivityManagement.getInstance().getActivitySize() > 1)
            overridePendingTransition(com.scorpio.baselibrary.R.anim.slide_in_left, com.scorpio.baselibrary.R.anim.slide_out_right);
    }
}
